home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / bsd / ufs / lockf.h < prev    next >
C/C++ Source or Header  |  1995-02-14  |  4KB  |  124 lines

  1. /*
  2.  * Copyright (c) 1991 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * This code is derived from software contributed to Berkeley by
  6.  * Scooter Morris at Genentech Inc.
  7.  *
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in the
  15.  *    documentation and/or other materials provided with the distribution.
  16.  * 3. All advertising materials mentioning features or use of this software
  17.  *    must display the following acknowledgement:
  18.  *    This product includes software developed by the University of
  19.  *    California, Berkeley and its contributors.
  20.  * 4. Neither the name of the University nor the names of its contributors
  21.  *    may be used to endorse or promote products derived from this software
  22.  *    without specific prior written permission.
  23.  *
  24.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34.  * SUCH DAMAGE.
  35.  *
  36.  *    @(#)lockf.h    7.1 (Berkeley) 2/1/91
  37.  */
  38.  
  39. #ifndef    _LOCKF_H
  40. #define _LOCKF_H
  41.  
  42. #if POSIX_KERN
  43.  
  44. #include <sys/types.h>
  45. #include <sys/vnode.h>
  46.  
  47. /*
  48.  * The lf_svnode structure is a kernel structure which shadows the real
  49.  * vnode structure.  There is one lf_svnode structure for each vnode that
  50.  * has locks.  Each structure points to a list lockf structures.  These
  51.  * shadow vnode structures are kept in a hash list for efficiency.
  52.  *
  53.  * Note: This structure is added so as not to add fields
  54.  *       to the inode or vnode structure.  
  55.  */
  56. struct lf_svnode {
  57.     struct vnode        *lf_vnodep;    /* Pointer to vnode and id. */
  58.     struct lockf        *lf_lockfp;    /* List of lockf structures. */
  59.     int            lf_refcnt;    /* Reference counter. */
  60.     struct lf_svnode    *lf_next;    /* Pointer to next struct */
  61. };
  62.  
  63. /*
  64.  * Hash list for shadow vnode (lf_svnode) structures.
  65.  */
  66. #define LF_SVNODE_HSZ    64
  67. #define LF_SVNODE_HASH(num)    ((num) & (LF_SVNODE_HSZ - 1))
  68. extern struct lf_svnode    *lf_svnode_hash[];
  69.  
  70. /*
  71.  * The lockf structure is a kernel structure which contains all the
  72.  * information associated with a byte range lock. The lockf structures
  73.  * are linked into a shadow vnode structure. Locks are sorted by the
  74.  * starting byte of the lock for efficiency.
  75.  */
  76. struct lockf {
  77.     short            lf_flags;     /* Lock semantics: LF_WAIT,
  78.                           * LF_NOWAIT
  79.                           */
  80.     short            lf_type;     /* Lock type: F_RDLCK,
  81.                           * F_WRLCK, F_UNLCK
  82.                           */
  83.     off_t            lf_start;     /* The byte # of the start of
  84.                           * the lock
  85.                           */
  86.     off_t            lf_end;         /* The byte # of the end of
  87.                           * the lock (-1=EOF)
  88.                           */
  89.     struct posix_proc    *lf_posix_procp; /* The id of the resource
  90.                           * holding the lock
  91.                           */
  92.     struct lf_svnode    *lf_svnodep;     /* Back pointer to the shadow
  93.                           * vnode structure
  94.                           */
  95.     struct lockf        *lf_next;     /* A pointer to the next lock
  96.                           * on this vnode
  97.                           */
  98.     struct lockf        *lf_block;     /* The list of blocked locks */
  99. };
  100.  
  101. /*
  102.  * Maximum length of sleep chains to traverse to try and detect deadlock.
  103.  */
  104. #define LF_MAXDEPTH 50
  105.  
  106. /*
  107.  * Flags to indicate blocking or nonblocking locking.
  108.  */
  109. #define LF_NOWAIT    01
  110. #define LF_WAIT        02
  111.  
  112. /*
  113.  * Public lock manipulation routine
  114.  */
  115. extern int lf_lockctl();
  116.  
  117. #ifdef    LOCKF_DEBUG
  118. extern int lockf_debug;
  119. #endif    /* LOCKF_DEBUG */
  120.  
  121. #endif    /* POSIX_KERN */
  122.  
  123. #endif    /* _LOCKF_H */
  124.